package com.mind.invoice.controller;

import java.util.List;

import com.mind.common.web.page.TableDataInfo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mind.common.annotation.Log;
import com.mind.common.web.controller.BaseController;
import com.mind.common.core.domain.AjaxResult;
import com.mind.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.mind.invoice.domain.AjJsAdapter;
import com.mind.invoice.service.IAjJsAdapterService;
import com.mind.common.utils.poi.ExcelUtil;

/**
 * 函数Controller
 * 
 * @author today
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/invoice/adapter")
@Tag(name = "函数管理", description = "函数管理")
public class AjJsAdapterController extends BaseController
{
    @Autowired
    private IAjJsAdapterService ajJsAdapterService;

    /**
     * 查询函数列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:adapter:list')")
    @GetMapping("/list")
    @Operation(summary = "查询函数列表", description = "查询函数列表")
    public TableDataInfo list(AjJsAdapter ajJsAdapter)
    {
        startPage();
        List<AjJsAdapter> list = ajJsAdapterService.selectAjJsAdapterList(ajJsAdapter);
        return getDataTable(list);
    }

    /**
     * 导出函数列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:adapter:export')")
    @Log(title = "函数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出函数列表", description = "查询函数列表")
    public void export(HttpServletResponse response, AjJsAdapter ajJsAdapter)
    {
        List<AjJsAdapter> list = ajJsAdapterService.selectAjJsAdapterList(ajJsAdapter);
        ExcelUtil<AjJsAdapter> util = new ExcelUtil<AjJsAdapter>(AjJsAdapter.class);
        util.exportExcel(response, list, "函数数据");
    }

    /**
     * 获取函数详细信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:adapter:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取函数详细信息", description = "获取函数详细信息")
    public AjaxResult getInfo(@Parameter(description ="函数Id",required=true) @PathVariable("id") Long id)
    {
        return success(ajJsAdapterService.selectAjJsAdapterById(id));
    }

    /**
     * 新增函数
     */
    @PreAuthorize("@ss.hasPermi('invoice:adapter:add')")
    @Log(title = "函数", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增函数", description = "新增函数")
    public AjaxResult add(@RequestBody AjJsAdapter ajJsAdapter)
    {
        return toAjax(ajJsAdapterService.insertAjJsAdapter(ajJsAdapter));
    }

    /**
     * 修改函数
     */
    @PreAuthorize("@ss.hasPermi('invoice:adapter:edit')")
    @Log(title = "函数", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改函数", description = "修改函数")
    public AjaxResult edit(@RequestBody AjJsAdapter ajJsAdapter)
    {
        return toAjax(ajJsAdapterService.updateAjJsAdapter(ajJsAdapter));
    }

    /**
     * 删除函数
     */
    @PreAuthorize("@ss.hasPermi('invoice:adapter:remove')")
    @Log(title = "函数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @Operation(summary = "删除函数", description = "删除函数")
    public AjaxResult remove(@Parameter(description ="函数Id",required=true) @PathVariable Long[] ids)
    {
        return toAjax(ajJsAdapterService.deleteAjJsAdapterByIds(ids));
    }
}
